package com.uh.calculation.batchOperator;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.uh.calculation.bean.SqlWriteBean;
import com.uh.calculation.bean.WarnEnterpriseRecord;
import com.uh.calculation.bean.WarnJiSuanBean;
import com.uh.microservice.core.dao.JdbcDao;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

//import com.uh.calculation.util.GetFileds;

@Data
/**
 *  统计人员计算
 */
public class TjryBathOperator {
    private JdbcDao jdbcDao;
    private WarnJiSuanBean warnJiSuanBean;
    private SqlWriteBean sqlWriteBean;

    public TjryBathOperator(JdbcDao jdbcDao, WarnJiSuanBean warnJiSuanBean, SqlWriteBean sqlWriteBean){
        this.jdbcDao=jdbcDao;
        this.warnJiSuanBean=warnJiSuanBean;
        this.sqlWriteBean=  sqlWriteBean;
    }

    public void jisuan(JSONArray ls, String key, String dimension) {
        this.warnJiSuanBean = warnJiSuanBean;
        if (ls==null||ls.size() == 0) {
            return;
        }
        int warnNum = 0;
        int i = 1;//统计变动次数
        String human = "firstName";//存储 填表人姓名
        String timeCode = "";
        for (int j = 0; j < ls.size(); j++) {
        //for (Map<String, Object> map : ls) {
            JSONObject map = ls.getJSONObject(j);
            String mapHuman = (String) map.get(key);
            timeCode = (String) map.get("time_code");
            if (mapHuman == null || "".equals(mapHuman)) {
                continue;
            }
            if (human.equals("firstName")) {
                human = mapHuman;
                i = 1;
                continue;
            }
            if (human.equals(mapHuman)) {
                i++;
                if (i >= 4) {
                    warnNum = 0;
                }
            } else {
                i = 1;
                warnNum = 20;
                human = mapHuman;
            }

        }
        //WarnEnterpriseRecord warnEnterpriseRecord = new WarnEnterpriseRecord();
        /*warnEnterpriseRecord.setWarnFactor(String.valueOf(warnNum));
        warnEnterpriseRecord.setCreateTime(new Date());
        warnEnterpriseRecord.setDimension(dimension);//预警类型
        warnEnterpriseRecord.setYearIsMonth(timeCode);//预警时间
        warnEnterpriseRecord.setWarnType(warnJiSuanBean.getWarnType());
        if (warnJiSuanBean.getWarnEnterpriseRecords() == null) {
            warnJiSuanBean.setWarnEnterpriseRecords(new ArrayList<WarnEnterpriseRecord>());
        }
        warnJiSuanBean.getWarnEnterpriseRecords().add(warnEnterpriseRecord);*/
    }

}
